//
//  QDCopygraphViewController.m
//  QingDaoMetro
//
//  Created by 王成龙 on 2018/5/29.
//  Copyright © 2018年 Duxin. All rights reserved.
//

#import "QDCopygraphViewController.h"
#import "QDMetroClient-Swift.h"

@interface QDCopygraphViewController ()<UITextFieldDelegate>

@property (nonatomic, weak) IBOutlet UIButton *chooseBtn;
@property (nonatomic, weak) IBOutlet UITextField *problemTf;//原因
@property (nonatomic, weak) IBOutlet UILabel *lastStatiionLable;

@property (nonatomic, assign) BOOL first;
@property (nonatomic, strong) NSString * type;

@end

@implementation QDCopygraphViewController
/**
 * 提示用户
 */
- (void)addAlert{
    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"自助补站" message:@"如果你的乘车码可以正常使用，请不要随意使用该功能，根据你提交的信息，可能会产生相关费用。" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    [actionSheet addAction:action1];
    [self presentViewController:actionSheet animated:YES completion:nil];

}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"自助补站";
    [self addAlert];
    
    [self.view addUIControlHandler:^(UIView * _Nonnull view) {
        [view endEditing:true];
    }];
}



/*
 *选择 进站还是出站 弹出actionsheet
 */
- (IBAction)chooseBtn:(id)sender {

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"自助补站" message:@"请选择是出站还是进站" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"进站" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.first  =YES;
        self.type = @"01";
        [self.chooseBtn setTitle:@"进站" forState:UIControlStateNormal];
        [self.chooseBtn setTitleColor:RITLColorFromRGB(0x4A4949) forState:UIControlStateNormal];
        self.lastStatiionLable.text = @"上次进站信息";
    }];

    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"出站" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.first = YES;
        self.type = @"02";
        [self.chooseBtn setTitle:@"出站" forState:UIControlStateNormal];
        [self.chooseBtn setTitleColor:RITLColorFromRGB(0x4A4949) forState:UIControlStateNormal];
         self.lastStatiionLable.text = @"上次出站信息";
    }];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [actionSheet addAction:action1];
    [actionSheet addAction:action2];
    [actionSheet addAction:action3];
    [self presentViewController:actionSheet animated:YES completion:nil];
}


//上次离站信息-跳转信息
- (IBAction)lastStation:(id)sender {
    
    /// 填出选择站点控制器
    [self pushSelectedStationViewController];

    
//    WEAK_SELF;
//    QDCLSelectStationViewController * station = [[QDCLSelectStationViewController alloc]init];
//    station.returnValueBlock = ^(NSString *URLStr, NSString *Xlocation, NSString *Ylocation, NSString *stationName, NSString *lineName) {
//        QDLog(@"站名字：%@",URLStr);
//        self.second = YES;
//        [weakSelf.stationName setTitle:stationName forState:UIControlStateNormal];
//        [weakSelf.stationName setTitleColor:HEXAlphaColor(@"#4A4949", 1) forState:UIControlStateNormal];
//        weakSelf.outStationId = URLStr;
//    };
//    [self.navigationController pushViewController:station animated:YES];
}



//确定按钮
- (IBAction)sureBtn:(id)sender
{
    if (!self.first) {
        ShowMBHUD(@"请选择进站还是出站", self.view);
        return;
    }
    if (!self.second) {
        ShowMBHUD(@"请选择上次站点信息", self.view);
        return;
    }
    
    NSLog(@"自助补站啦!");

    //TODO: 进行自助补站
    [self requestSupplementWithType:self.type stationId:self.outStationId explain:self.problemTf.text];
    
    
//    [QDBrakeMachineModel supplenmentProblemWithType:self.type withStationID:self.outStationId withReason:self.problemTf.text success:^(NSString *message) {
//        QDLog(@"message=%@",message);
//        [MBProgressHUD showText:message];
//        [self.navigationController popViewControllerAnimated:true];
//    }];
}



-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
